Skip to content

Spiral Matrix ​

Spiral Matrix — LeetCode

Return all the elements of an m x n matrix in spiral order.

Approach ​

Keep a dx and dy to indicate direction of movement. Ending condition is i >= m*n. Replace the visited element with some garbage.

Remarks ​

https://youtu.be/pLjhGbKMxL4?si=uCEUBkU9Wkx5Y-Jl